package com.shaobufan.museum.controllar;

import com.shaobufan.museum.common.BaseResponse;
import com.shaobufan.museum.common.ErrorCode;
import com.shaobufan.museum.common.ResultUtils;
import com.shaobufan.museum.service.UserVerificationService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

import static com.shaobufan.museum.contant.EmailContent.EMAIL_SEND_FAIL;
import static com.shaobufan.museum.contant.EmailContent.EMAIL_SEND_SUCCESS;

/**
 * 验证码请求
 */
@RestController
@RequestMapping("/user")
public class CaptchaController {
    @Resource
    UserVerificationService userVerificationService;

    @ApiOperation("获取验证码")
    @GetMapping("/captcha")
    public BaseResponse<Boolean> getUserCaptcha(String userEmail, String uuid) throws IOException {

        Integer codeResult = userVerificationService.sendVerificationCode(userEmail, uuid);
        if (codeResult == 1) {
            return ResultUtils.success(true, EMAIL_SEND_SUCCESS);
        }
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR, EMAIL_SEND_FAIL);
    }
}